#!/usr/bin/python3
# author luke
# 2024年03月06日下午 11:26

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


def create_linked_list(lst):
    if not lst:
        return None
    else:
        head = ListNode(lst[0])
        head.next = create_linked_list(lst[1:])
        return head


# 使用列表创建链表
values = [1, 2, 3, 4, 5]
linked_list = create_linked_list(values)
# print(linked_list)
current = linked_list
result = []
while current:
    result.append(current.val)
    current = current.next
print(result)
